#!/usr/local/bin/perl

# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
# 
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
# 
# The Original Code is Komodo code.
# 
# The Initial Developer of the Original Code is ActiveState Software Inc.
# Portions created by ActiveState Software Inc are Copyright (C) 2000-2007
# ActiveState Software Inc. All Rights Reserved.
# 
# Contributor(s):
#   ActiveState Software Inc
# 
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
# 
# ***** END LICENSE BLOCK *****

# Conscript for building the scintilla dll (with lexer)
#   Neil Hodgson provides a makefile to build this so we are no going to
#   duplicate that, however, to ensure rebuilding as necessary the
#   Command that call the makefile should have the proper dependencies
#   (i.e. inputs). In fact, to work with the build->src link they *must* all
#   be listed (this is a good thing). These will have to be kept in sync.

Import(
    'cons',
    'buildType',
    'mozBin',
    'unsiloedPythonExe',
    'ranRegxpcomStateFileName',
);

# this is what we want from the scintilla build process
$pluginName = '../bin/SciLexer.dll';

%consLocal = $cons->copy();
my $LDFLAGS = $consLocal{'LDFLAGS'};

# The SciMoz build on Linux explicitly links the Lex*.o files from the
# scintilla build AND with Cons multiple targets for a "Command" cannot be
# specified, so have to specify a makefile call for each platform.
# Use one entry per line for ease of maintenance.  Bits are cheap.
my @lexers = qw(
    A68k
    Abaqus
    Ada
    APDL
    Asm
    Asn1
    ASY
    AU3
    AVE
    AVS
    Baan
    Bash
    Basic
    BibTeX
    Bullant
    Caml
    CoffeeScript
    CLW
    Cmake
    COBOL
    CoffeeScript
    Conf
    CPP
    Crontab
    Csound
    CSS
    D
    DMAP
    DMIS
    ECL
    Eiffel
    Erlang
    EScript
    Flagship
    Forth
    Fortran
    GAP
    Gui4Cli
    Haskell
    Hex
    HTML
    Inno
    Kix
    KVIrc
    LaTeX
    Lisp
    Lout
    Lua
    Magik
    Markdown
    Matlab
    Metapost
    MMIXAL
    Modula
    MPT
    MSSQL
    MySQL
    Nimrod
    Nsis
    Opal
    OScript
    Others
    Pascal
    PB
    Perl
    PLM
    PO
    POV
    PowerPro
    PowerShell
    Progress
    PS
    Python
    R
    Rebol
    Registry
    Ruby
    Rust
    Scriptol
    Smalltalk
    SML
    Sorcus
    Specman
    Spice
    SQL
    STTXT
    TACL
    TADS3
    TAL
    TCMD
    Tcl
    TeX
    Txt2tags
    UDL
    VB
    Verilog
    VisualProlog
    VHDL
    XSLT
    YAML
);
@lexers = map { "../lexers/Lex$_.cxx" } @lexers;

$cons->Command(
    [$pluginName],              # %0
    "scintilla.mak",            # %1
    "../scripts/HFacer.py",     # %2
    "../scripts/Face.py",
    "../scripts/FileGenerator.py",
    "../scripts/LexGen.py",
    "../include/ILexer.h",
    "../include/Platform.h",
    "../include/SciLexer.h",
    "../include/Scintilla.h",
    "../include/Scintilla.iface",
    "../include/ScintillaWidget.h",


    "../lexlib/Accessor.cxx",
    "../lexlib/Accessor.h",
    "../lexlib/CharacterCategory.cxx",
    "../lexlib/CharacterCategory.h",
    "../lexlib/CharacterSet.cxx",
    "../lexlib/CharacterSet.h",
    "../lexlib/LexAccessor.h",
    "../lexlib/LexerBase.cxx",
    "../lexlib/LexerBase.h",
    "../lexlib/LexerModule.cxx",
    "../lexlib/LexerModule.h",
    "../lexlib/LexerNoExceptions.cxx",
    "../lexlib/LexerNoExceptions.h",
    "../lexlib/LexerSimple.cxx",
    "../lexlib/LexerSimple.h",
    "../lexlib/OptionSet.h",
    "../lexlib/PropSetSimple.cxx",
    "../lexlib/PropSetSimple.h",
    "../lexlib/SparseState.h",
    "../lexlib/StringCopy.h",
    "../lexlib/StyleContext.cxx",
    "../lexlib/StyleContext.h",
    "../lexlib/SubStyles.h",
    "../lexlib/WordList.cxx",
    "../lexlib/WordList.h",

    "../src/AutoComplete.cxx",
    "../src/AutoComplete.h",
    "../src/CallTip.cxx",
    "../src/CallTip.h",
    "../src/CaseConvert.cxx",
    "../src/CaseConvert.h",
    "../src/CaseFolder.cxx",
    "../src/CaseFolder.h",
    "../src/Catalogue.cxx",
    "../src/Catalogue.h",
    "../src/CellBuffer.cxx",
    "../src/CellBuffer.h",
    "../src/CharClassify.cxx",
    "../src/CharClassify.h",
    "../src/ContractionState.cxx",
    "../src/ContractionState.h",
    "../src/Decoration.cxx",
    "../src/Decoration.h",
    "../src/Document.cxx",
    "../src/Document.h",
    "../src/Editor.cxx",
    "../src/Editor.h",
    "../src/EditModel.cxx",
    "../src/EditModel.h",
    "../src/EditView.cxx",
    "../src/EditView.h",
    "../src/ExternalLexer.cxx",
    "../src/ExternalLexer.h",
    "../src/FontQuality.h",
    "../src/Indicator.cxx",
    "../src/Indicator.h",
    "../src/KeyMap.cxx",
    "../src/KeyMap.h",
    "../src/LineMarker.cxx",
    "../src/LineMarker.h",
    "../src/MarginView.cxx",
    "../src/MarginView.h",
    "../src/Partitioning.h",
    "../src/PerLine.cxx",
    "../src/PerLine.h",
    "../src/PositionCache.cxx",
    "../src/PositionCache.h",
    "../src/RESearch.cxx",
    "../src/RESearch.h",
    "../src/RunStyles.cxx",
    "../src/RunStyles.h",
    "../src/ScintillaBase.cxx",
    "../src/ScintillaBase.h",
    "../src/Selection.cxx",
    "../src/Selection.h",
    "../src/SplitVector.h",
    "../src/Style.cxx",
    "../src/Style.h",
    "../src/UniConversion.cxx",
    "../src/UniConversion.h",
    "../src/UnicodeFromUTF8.h",
    "../src/ViewStyle.cxx",
    "../src/ViewStyle.h",
    "../src/XPM.cxx",
    "../src/XPM.h",
    @lexers,
#    "Margin.cur",
#    "PlatformRes.h",
    #"CheckD2D.cxx",
    "HanjaDic.h",
    "HanjaDic.cxx",
    "PlatWin.h",
    "PlatWin.cxx",
    "Scintilla.def",
    "ScintillaWin.cxx",
    "ScintRes.rc",
    "../bin/empty.txt",   # as for scintilla dist, only there to create bin dir

    "libpcre.lib", # built and installed from contrib/pcre
    "../include/pcre.h", # installed from contrib/pcre

    qq(
        $unsiloedPythonExe bin/run-in-dir.py %2:d python HFacer.py
        set LINK=$LDFLAGS && $unsiloedPythonExe bin/run-in-dir.py %1:d nmake /nologo QUIET=0 $pluginName -f %1:f
    )
);


# install it
$cons->Install($mozBin, $pluginName);

# Running regxpcom depends on SciLexer.dll being installed.
$cons->Depends($ranRegxpcomStateFileName, $pluginName);
